package net.chenyan.server.repository;/**
 * @author chenyan
 * @createTime 2022/5/10 23:37
 * @description description
 */

import net.chenyan.server.po.Album;
import net.chenyan.server.po.List;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.Pageable;
import org.springframework.data.jpa.repository.JpaSpecificationExecutor;
import org.springframework.data.jpa.repository.Query;
import org.springframework.data.repository.PagingAndSortingRepository;
import org.springframework.stereotype.Repository;

/**
 *@description: TODO
 *@author: chenyan
 *@create: 2022/5/10 23:37
 */

@Repository
public interface ListRepository extends PagingAndSortingRepository<List,Integer>, JpaSpecificationExecutor<List> {
    //分页查询（根据用户id分页查询所有数据）
    @Query(value = "select *  from list l where l.create_user_id=?1",nativeQuery = true)
    Page<List> findByCreateUserId(Pageable pageable, int userId);

    //分页查询（分页查询所有数据）
    @Query(value = "select *  from list l ",nativeQuery = true)
    Page<List> findList(Pageable pageable);

    //分页查询（分页查询所有数据按照热度排序）
    @Query(value = "select *  from list l order by liked_num desc",nativeQuery = true)
    Page<List> findListByLike(Pageable pageable);

    //分页查询（分页查询所有数据按照更新时间排序）
    @Query(value = "select *  from list l order by created_time desc ",nativeQuery = true)
    Page<List> findListByCreateTime(Pageable pageable);

    //分页查询（根据用户id分页查询所有用户收藏的数据）
    @Query(value = "select l.*  from user_list ul inner join user u on u.id=ul.user_id inner join list l on l.id=ul.list_id where user_id=?1 and is_collect=1",nativeQuery = true)
    Page<List> findListByUserId(int userId, Pageable pageable);

}
